// 数据类型

// shared.js =====================
const cache = {};

// a.js ==================
cache['foo'] = Math.random();

// b.js ==================
cache['foo'] = '123';

console.log(cache);

// 通过Symbol创建的值是独一无二的
const s = Symbol();
console.log(typeof s);

console.log(Symbol() === Symbol());

const obj = {
  [Symbol()]: '789',
};
obj[Symbol()] = '123';
obj[Symbol()] = '456';

console.log(obj);

const name = Symbol();
const obj1 = {
  [name]: 'cuvee',
  say: function () {
    console.log(this[name]);
  },
};

console.log(obj1.say());

// 注意
console.log(Symbol('foo') === Symbol('foo'));

// 复用一个相同的symbol值，调用静态方法for，注意这儿一定要是字符串
const s1 = Symbol.for('foo');
const s2 = Symbol.for('foo');

console.log(s1 === s2);

console.log(Symbol.iterator);
console.log(Symbol.hasInstance);

// 自定义toString
const obj2 = {
  [Symbol.toStringTag]: 'XObject',
};

console.log(obj2.toString());

// 通过for...in 和 Object.keys遍历不到Symbol这个key

const obj3 = {
  [Symbol()]: 'cuvee',
  age: 30,
};

for (const key in obj3) {
  console.log(key);
}

console.log(Object.keys(obj3));

console.log(Object.getOwnPropertySymbols(obj3));
